/*
cmfit
Copyright (C) 2000-2007 Andreas Bengtsson

Email: anteman@users.sourceforge.net

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

// Checks for any unwanted chars for filenames
function ischarsok($str){
	var $res=true;
	if((escape($str)).indexOf('%')!=-1){
		$res=false;
	}
	if($str.indexOf('*') != -1){ $res=false;}
	if($str.indexOf('@') != -1){ $res=false;}
	if($str.indexOf('+') != -1){ $res=false;}
	if($str.indexOf('.') != -1){ $res=false;}
	if($str.indexOf('/') != -1){ $res=false;}
	if($str.indexOf('\\') != -1){ $res=false;}
	return $res;
}

// URLencodes a string
// javascript escape() does not escape these; * @ - _ + . /
// "ABC".charCodeAt(0) // returns 65  charAt(index)
// "*@-_+./ "="%2A%40-_%2B.%2F%20"
	
function rawurlencode($astr){
  var $ret="";
  var $str=escape($astr);
  for(i=0;i<$str.length;i++){
	if($str.charAt(i)=="*"){
		$ret+="%2A";
	}else
	if($str.charAt(i)=='@'){
		$ret+="%40";
	}else
	if($str.charAt(i)=='+'){
		$ret+="%2B";
	}else
	if($str.charAt(i)=='/'){
		$ret+="%2F";
	}else
	if($str.charAt(i)==' '){
		$ret+="+";
	}else{
		$ret+=$str.charAt(i);
	}
  }
  return $ret;
}

// display functions for the picture selector
function picselIsHidden(){return document.getElementById('cmfit_selector').style.visibility!='visible';}
function picselIsVisible(){return document.getElementById('cmfit_selector').style.visibility=='visible';}

function hidePicsel(){
sel=document.getElementById('cmfit_selector');
sel.style.visibility='hidden';
}

function showPicsel(){
sel=document.getElementById('cmfit_selector');
xoff=(document.all)?document.body.scrollLeft:window.pageXOffset;
yoff=(document.all)?document.body.scrollTop:window.pageYOffset;
sel.style.left=xoff+"px";
sel.style.top=yoff+"px";
sel.style.width="50%";
sel.style.height="80%";
sel.style.visibility='visible';
}


//Show file selector
function picsel(src){
	if(picselIsVisible())
	{
		// Just toggle the selector if clicked twice
		hidePicsel();
	}
	else
	{
		cmfit_picsel_tag=src;
		showPicsel();
	}
}

// User has selected a file
function selectedpic(src){
	hidePicsel();
	document.getElementById(cmfit_picsel_tag+"__id").value=src;
	document.getElementById(cmfit_picsel_tag+"__pic").src=src;
	cmfit_picsel_tag="";
}

// will return the selected pic source back to the editor frame
function clickedpic(src){
	parent.selectedpic(src);
}

// This var holds the selected picture
var cmfit_picsel_selection_src="none";
var cmfit_picsel_tag="";

// display functions for the picture selector
function IsHidden(){return document.getElementById('cmfit_selector').style.visibility!='visible';}
function picselIsVisible(){return document.getElementById('cmfit_selector').style.visibility=='visible';}

// Toggle a URL input form
function cmfit_urlsel(name){
if(document.getElementById('cmfit_urlsel_'+name).style.visibility=='visible'){
	document.getElementById('cmfit_urlsel_'+name).style.visibility='hidden';
}else{
	document.getElementById('cmfit_urlsel_'+name).style.visibility='visible';
}

}


if (document.layers)document.captureEvents(Event.MOUSEMOVE); 
document.onmousemove=myEventHandler;

function myEventHandler(e) {
   var Text= 'Coordinates: ';
   if (document.layers){
	Text += e.pageX+','+e.pageY;
	}else{ event.x+','+event.y; }
  // Text += " Std:"+ e.clientX+','+e.clientY;
   window.status= Text;
}

/**http://www.howtocreate.co.uk/tutorials/javascript/eventinfo*/
//document.onmousemove = alertCoord;
function alertCoord(e) {
  var xcoord, ycoord;
  if( !e ) { e = window.event; }
  if( !e ) { return; }
  if( typeof( e.pageX ) == 'number' ) {
    xcoord = e.pageX;
    ycoord = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    xcoord = e.clientX;
    ycoord = e.clientY;
    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      xcoord += document.body.scrollLeft;
      ycoord += document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      xcoord += document.documentElement.scrollLeft;
      ycoord += document.documentElement.scrollTop;
    }
  } else { return; }
  window.alert('Mouse coordinates are ('+xcoord+','+ycoord+')');
}



